const app = getApp()
Page({
  data: {
    defaultData: {
      title: "", // 导航栏标题
      showHome: false, //是否显示回到首页按钮
      showBack: true, //是否显示返回按钮
      showLogo: false, //是否显示logo
      bgColor: 'transparent',
    },
    baseUrl: app.baseUrl,
    version: app.globalData.version,
    navBarHeight: app.globalData.navBarHeight,
    copyList: [{
        id: 'lxbd',
        img: 'copy-lxbd-bg',
        copyTitle1: '重庆两江新区新溪置业发展有限公司',
        copyTitle2: '500500020015003002772',
        copyTitle3: '交行重庆渝中支行',
        copyTitle4: '组团+房号+诚意金/定金/房款',
        allCopyTitle: '户 名:重庆两江新区新溪置业发展有限公司,账号:500500020015003002772,开户行:交行重庆渝中支行,备 注:组团+房号+诚意金/定金/房款'
      },
      {
        id: 'byx',
        img: 'copy-byx-bg',
        copyTitle1: '重重庆万悦置业有限公司',
        copyTitle2: '651967394',
        copyTitle3: '民生银行重庆两江金开支行',
        copyTitle4: '组团+房号+诚意金/定金/房款',
        allCopyTitle: '户 名:重重庆万悦置业有限公司,账号:651967394,开户行:民生银行重庆两江金开支行,备 注:组团+房号+诚意金/定金/房款'
      },
      {
        id: 'yj',
        img: 'copy-yj-bg',
        copyTitle1: '重庆万悦置业有限公司',
        copyTitle2: '650794893',
        copyTitle3: '民生银行重庆两江金开支行',
        copyTitle4: '组团+房号+诚意金/定金/房款',
        allCopyTitle: '户 名:重庆万悦置业有限公司,账号:650794893,开户行:民生银行重庆两江金开支行,备 注:组团+房号+诚意金/定金/房款'
      }
    ],
    currentCopyList: [],
    shareTitle: '',
    shareImg: '',
    id: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var that = this;
    const {
      id
    } = options
    const {
      copyList
    } = this.data
    if (id) {
      this.setData({
        currentCopyList: copyList.find(el => el.id === id)
      })
    } else {
      this.setData({
        currentCopyList: copyList.find(el => el.id === 'yj')
      })
    }

    that.setData({
      id: id
    })

    //调用分享
    that.getShareInfo(id);
  },

  //获取微信分享信息
  getShareInfo(id) {
    var that = this;
    var imgId = 0;
    if (id == 'byx') {
      imgId = 45;
    } else if (id == 'lxbd') {
      imgId = 46;
    } else {
      imgId = 47;
    }
    wx.request({
      url: that.data.baseUrl + 'getShareInfo.php',
      method: 'POST',
      data: {
        id: imgId
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        that.setData({
          shareTitle: res.data.shareTitle,
          shareImg: res.data.shareImg
        });
      },
      fail: function (res) {}
    });
  },


  copyBtn(e) {
    const {
      currentCopyList
    } = this.data
    const {
      type
    } = e.currentTarget.dataset
    console.log(currentCopyList[type]);
    wx.setClipboardData({
      data: currentCopyList[type],
      success(res) {
        wx.showToast({
          title: `已复制`,
          icon: 'none'
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    var that = this;
    return {
      title: that.data.shareTitle,
      path: '/pages/copy-page/copy-page?id='+that.data.id,
      imageUrl: that.data.shareImg,
      success: function (res) {

      },
      fail: function (res) {

      }
    }
  }
})